// cnpm i spark-md5 -S
import SparkMD5 from 'spark-md5'

export function md5File (file, fn) {
  let reader = new FileReader()
  reader.readAsBinaryString(file)
  reader.onload = e => {
    let imgFlag = e.target.result
    let spark = new SparkMD5()
    spark.appendBinary(imgFlag)
    // console.log(spark.end())
    let str = spark.end()
    fn && fn(str)
  }
}

export const md5Str = (str) => {
  let spark = new SparkMD5()
  spark.append(str)
  let aa = spark.end()
  return aa
}
